<?php
/**
 * 住院病史模型
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/8
 * Time: 10:20
 */
class ZhuyuanBingshiModel extends BaseModel
{
    // 获取住院基本信息 单条信息
    public function getZhuYuanBasicInfo($yiuan_id,$zhuyuan_id)
    {

        $data = DB::select()
            ->from("zhuyuan_basic_info")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    // 获取入院记录信息(住院病史)
    public function getZhuyuanBingshiInfo($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("bingshicaiji_riqi_time","zhusu")
            ->from("zhuyuan_bingshi")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    //住院总结
    public function getZhuYuanZongJie($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhuyuanyishi_id","zhuyuanyishi_name")
            ->from("zhuyuan_zongjie_info")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    //查询主治医师
    public function GetZhuZhiYishi($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhenduan_mingcheng")
            ->from("zhenduan_xiyi")
            ->where("zhixing_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("zhenduan_sub_type","=","主要诊断")
            ->and_where("zhixing_type","=","住院")
            ->and_where("zhenduan_type","=","入院确定诊断")
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    //获取诊断西医次要诊断
    public function GetZhenDuanXiyi($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhenduan_mingcheng")
            ->from("zhenduan_xiyi")
            ->where("zhixing_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("zhenduan_sub_type","=","次要诊断")
            ->and_where("zhixing_type","=","住院")
            ->and_where("zhenduan_type","=","入院确定诊断")
            ->execute()
            ->as_array();
        return $data;
    }

    //获取中医主要诊断
    public function GetZhongYiZhenDuan($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhenduan_mingcheng")
            ->from("zhenduan_zhongyi")
            ->where("zhixing_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("zhenduan_sub_type","=","主要诊断")
            ->and_where("zhixing_type","=","住院")
            ->and_where("zhenduan_type","=","入院确定诊断")
            ->execute()
            ->offsetGet(0);
        return $data;
    }

    //获取中医主要诊断 次要诊断
    public function GetZhongYiBingzheng($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhenduan_mingcheng")
            ->from("zhenduan_zhongyi")
            ->where("zhixing_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->and_where("zhenduan_sub_type","=","中医病症")
            ->and_where("zhixing_type","=","住院")
            ->and_where("zhenduan_type","=","入院确定诊断")
            ->execute()
            ->as_array();
        return $data;
    }
    //// 首次病程时间
    public function GetShouciBingli($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("record_time")
            ->from("zhuyuan_bingchengjilushouci")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    ////病程记录
    public function GetBingChengJilu($zhuyuan_id,$yiyuan_id)
    {
        $data = array();
        if(Yaconf::get("config$yiyuan_id.bingcheng_jilu_xianshi") == "v2")
        {
            $sqls = "select m.bingcheng_id as id,m.bingcheng_sub_leibie,m.record_time from
				(select a.bingcheng_id,a.bingcheng_sub_leibie,a.record_time from zhuyuan_bingchengjilu a,
				zhuyuan_basic_info b where a.zhuyuan_id = b.zhuyuan_id and a.zhuyuan_id='$zhuyuan_id' and a.record_time>=b.ruyuan_riqi_time)m
				group by m.bingcheng_id,m.bingcheng_sub_leibie,m.record_time";
            $data = DB::query(Database::SELECT, $sqls)->execute()->as_array();
        }else{
            $data = DB::select("id","bingcheng_sub_leibie","record_time")
                ->from("zhuyuan_bingchengjilu")
                ->where("zhuyuan_id","=",$zhuyuan_id)
                ->and_where("yiyuan_id","=",$yiyuan_id)
                ->execute()
                ->as_array();
        }
        return $data;
    }
    //获取病史
    public function GetBingShi($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("zhusu","xianbingshi","jiwangshi","gerenshi","hunyushi","yuejingshi","jiazushi")
            ->from("zhuyuan_bingshi")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }
    //获取体格检查
    public function GetTigeJianChan($zhuyuan_id,$yiyuan_id)
    {
        $data = DB::select("ruyuan_zhongyi_jiancha","jibenjiancha","ruyuan_zhuanke_jiancha","ruyuan_fuzhu_jiancha")
            ->from("zhuyuan_ruyuantigejiancha")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->execute()
            ->offsetGet(0);
        return $data;
    }

}